package com.koron.common.core.business.print;

import com.koron.common.core.business.print.bean.PrintTemplateBean;
import com.koron.common.core.business.print.printstandard.PrintStandardMapper;
import com.koron.print.PrintCenter;
import org.koron.ebs.mybatis.ADOConnection;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ReportProcessing {

    private static PrintImpl printer = new PrintImpl();
    public static byte[] content;


    public static void init() {
        PrintCenter.setPrintInterface(printer);
        PrintTemplateBean templateBean = ADOConnection.runTask("_default", factory -> {
            return factory.getMapper(PrintStandardMapper.class).getDefaultTemplateListById("测试填写模板内容");
        }, PrintTemplateBean.class);
        ReportProcessing.content = templateBean.getContent();//直接打开设计模板 默认内容
    }

    //清除过期报表任务
    public static void cleanPrintTask() {
        long timespam = new Date().getTime();
        List<String> taskList = new ArrayList<>();
        for (String strKey : ReportTask.task.keySet()) {
            if ((timespam - ReportTask.task.get(strKey).getTimeStamp()) > 1000 * 60 * 1440) {
                taskList.add(strKey);
            }
        }
        if (taskList.size() > 0) {
            for (String key : taskList) {
                ReportTask.task.remove(key);
            }
        }
    }

}
